package top.go2do.common.operationLog;

import cn.hutool.core.bean.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import top.go2do.common.module.OperationLogBO;

import java.util.Map;

/**
 * @Description
 * @Author xingyj
 * @CreateTime 2025/5/10 11:26
 */
@ConditionalOnProperty(prefix = "custom.log",name = "mode",havingValue = "redis")
@Service
public class RedisRecorder implements IRecorder{

    @Autowired
    private RedisTemplate<String, Object> redisStreamTemplate;

    @Value("${custom.log.redis.streamKey:operationLog}")
    private String logStreamKey;

    @Override
    public void sendMessage(OperationLogBO operationLogBO) {
        Map<String, Object> map = BeanUtil.beanToMap(operationLogBO);
        redisStreamTemplate.opsForStream().add(logStreamKey, map);
    }

}
